home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / tcl / tcl70b2.lha / tcl7.0b2 / tclUnix.h < prev    next >
C/C++ Source or Header  |  1993-07-19  |  7KB  |  284 lines

  1. /*
  2.  * tclUnix.h --
  3.  *
  4.  *    This file reads in UNIX-related header files and sets up
  5.  *    UNIX-related macros for Tcl's UNIX core.  It should be the
  6.  *    only file that contains #ifdefs to handle different flavors
  7.  *    of UNIX.  This file sets up the union of all UNIX-related
  8.  *    things needed by any of the Tcl core files.  This file
  9.  *    depends on configuration #defines in tclConfig.h
  10.  *
  11.  *    Much of the material in this file was originally contributed
  12.  *    by Karl Lehenbauer, Mark Diekhans and Peter da Silva.
  13.  *
  14.  * Copyright (c) 1991-1993 The Regents of the University of California.
  15.  * All rights reserved.
  16.  *
  17.  * Permission is hereby granted, without written agreement and without
  18.  * license or royalty fees, to use, copy, modify, and distribute this
  19.  * software and its documentation for any purpose, provided that the
  20.  * above copyright notice and the following two paragraphs appear in
  21.  * all copies of this software.
  22.  * 
  23.  * IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR
  24.  * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
  25.  * OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF
  26.  * CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  27.  *
  28.  * THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
  29.  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
  30.  * AND FITNESS FOR A PARTICULAR PURPOSE.  THE SOFTWARE PROVIDED HEREUNDER IS
  31.  * ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO
  32.  * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
  33.  *
  34.  * $Header: /user6/ouster/tcl/RCS/tclUnix.h,v 1.43 93/07/19 16:08:04 ouster Exp $ SPRITE (Berkeley)
  35.  */
  36.  
  37. #ifndef _TCLUNIX
  38. #define _TCLUNIX
  39.  
  40. #include <errno.h>
  41. #include <fcntl.h>
  42. #include <pwd.h>
  43. #include <signal.h>
  44. #include <sys/param.h>
  45. #include <sys/types.h>
  46. #ifdef USE_DIRENT2_H
  47. #   include "compat/dirent2.h"
  48. #else
  49. #   ifdef NO_DIRENT_H
  50. #    include "compat/dirent.h"
  51. #   else
  52. #    include <dirent.h>
  53. #   endif
  54. #endif
  55. #include <sys/file.h>
  56. #include <sys/stat.h>
  57. #ifndef NO_SYS_TIME_H
  58. #   include <sys/time.h>
  59. #else
  60. #   include <time.h>
  61. #endif
  62. #ifndef NO_SYS_WAIT_H
  63. #   include <sys/wait.h>
  64. #endif
  65. #ifdef HAVE_UNISTD_H
  66. #   include <unistd.h>
  67. #else
  68. #   include "compat/unistd.h"
  69. #endif
  70.  
  71. /*
  72.  * Not all systems declare the errno variable in errno.h. so this
  73.  * file does it explicitly.  The list of system error messages also
  74.  * isn't generally declared in a header file anywhere.
  75.  */
  76.  
  77. extern int errno;
  78. extern int sys_nerr;
  79. extern char *sys_errlist[];
  80.  
  81. /*
  82.  * The type of the status returned by wait varies from UNIX system
  83.  * to UNIX system.  The macro below defines it:
  84.  */
  85.  
  86. #ifndef NO_UNION_WAIT
  87. #   define WAIT_STATUS_TYPE union wait
  88. #else
  89. #   define WAIT_STATUS_TYPE int
  90. #endif
  91.  
  92. /*
  93.  * Supply definitions for macros to query wait status, if not already
  94.  * defined in header files above.
  95.  */
  96.  
  97. #ifndef WIFEXITED
  98. #   define WIFEXITED(stat)  (((*((int *) &(stat))) & 0xff) == 0)
  99. #endif
  100.  
  101. #ifndef WEXITSTATUS
  102. #   define WEXITSTATUS(stat) (((*((int *) &(stat))) >> 8) & 0xff)
  103. #endif
  104.  
  105. #ifndef WIFSIGNALED
  106. #   define WIFSIGNALED(stat) (((*((int *) &(stat)))) && ((*((int *) &(stat))) == ((*((int *) &(stat))) & 0x00ff)))
  107. #endif
  108.  
  109. #ifndef WTERMSIG
  110. #   define WTERMSIG(stat)    ((*((int *) &(stat))) & 0x7f)
  111. #endif
  112.  
  113. #ifndef WIFSTOPPED
  114. #   define WIFSTOPPED(stat)  (((*((int *) &(stat))) & 0xff) == 0177)
  115. #endif
  116.  
  117. #ifndef WSTOPSIG
  118. #   define WSTOPSIG(stat)    (((*((int *) &(stat))) >> 8) & 0xff)
  119. #endif
  120.  
  121. /*
  122.  * Supply macros for seek offsets, if they're not already provided by
  123.  * an include file.
  124.  */
  125.  
  126. #ifndef SEEK_SET
  127. #   define SEEK_SET 0
  128. #endif
  129.  
  130. #ifndef SEEK_CUR
  131. #   define SEEK_CUR 1
  132. #endif
  133.  
  134. #ifndef SEEK_END
  135. #   define SEEK_END 2
  136. #endif
  137.  
  138. /*
  139.  * The stuff below is needed by the "time" command.  If this
  140.  * system has no gettimeofday call, then must use times and the
  141.  * CLK_TCK #define (from sys/param.h) to compute elapsed time.
  142.  * Unfortunately, some systems only have HZ and no CLK_TCK, and
  143.  * some might not even have HZ.
  144.  */
  145.  
  146. #ifdef NO_GETTOD
  147. #   include <sys/times.h>
  148. #   include <sys/param.h>
  149. #   ifndef CLK_TCK
  150. #       ifdef HZ
  151. #           define CLK_TCK HZ
  152. #       else
  153. #           define CLK_TCK 60
  154. #       endif
  155. #   endif
  156. #endif
  157.  
  158. /*
  159.  * Define access mode constants if they aren't already defined.
  160.  */
  161.  
  162. #ifndef F_OK
  163. #    define F_OK 00
  164. #endif
  165. #ifndef X_OK
  166. #    define X_OK 01
  167. #endif
  168. #ifndef W_OK
  169. #    define W_OK 02
  170. #endif
  171. #ifndef R_OK
  172. #    define R_OK 04
  173. #endif
  174.  
  175. /*
  176.  * On systems without symbolic links (i.e. S_IFLNK isn't defined)
  177.  * define "lstat" to use "stat" instead.
  178.  */
  179.  
  180. #ifndef S_IFLNK
  181. #   define lstat stat
  182. #endif
  183.  
  184. /*
  185.  * Define macros to query file type bits, if they're not already
  186.  * defined.
  187.  */
  188.  
  189. #ifndef S_ISREG
  190. #   ifdef S_IFREG
  191. #       define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
  192. #   else
  193. #       define S_ISREG(m) 0
  194. #   endif
  195. # endif
  196. #ifndef S_ISDIR
  197. #   ifdef S_IFDIR
  198. #       define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
  199. #   else
  200. #       define S_ISDIR(m) 0
  201. #   endif
  202. # endif
  203. #ifndef S_ISCHR
  204. #   ifdef S_IFCHR
  205. #       define S_ISCHR(m) (((m) & S_IFMT) == S_IFCHR)
  206. #   else
  207. #       define S_ISCHR(m) 0
  208. #   endif
  209. # endif
  210. #ifndef S_ISBLK
  211. #   ifdef S_IFBLK
  212. #       define S_ISBLK(m) (((m) & S_IFMT) == S_IFBLK)
  213. #   else
  214. #       define S_ISBLK(m) 0
  215. #   endif
  216. # endif
  217. #ifndef S_ISFIFO
  218. #   ifdef S_IFIFO
  219. #       define S_ISFIFO(m) (((m) & S_IFMT) == S_IFIFO)
  220. #   else
  221. #       define S_ISFIFO(m) 0
  222. #   endif
  223. # endif
  224. #ifndef S_ISLNK
  225. #   ifdef S_IFLNK
  226. #       define S_ISLNK(m) (((m) & S_IFMT) == S_IFLNK)
  227. #   else
  228. #       define S_ISLNK(m) 0
  229. #   endif
  230. # endif
  231. #ifndef S_ISSOCK
  232. #   ifdef S_IFSOCK
  233. #       define S_ISSOCK(m) (((m) & S_IFMT) == S_IFSOCK)
  234. #   else
  235. #       define S_ISSOCK(m) 0
  236. #   endif
  237. # endif
  238.  
  239. /*
  240.  * Make sure that MAXPATHLEN is defined.
  241.  */
  242.  
  243. #ifndef MAXPATHLEN
  244. #   ifdef PATH_MAX
  245. #       define MAXPATHLEN PATH_MAX
  246. #   else
  247. #       define MAXPATHLEN 2048
  248. #   endif
  249. #endif
  250.  
  251. /*
  252.  * Make sure that L_tmpnam is defined.
  253.  */
  254.  
  255. #ifndef L_tmpnam
  256. #   define L_tmpnam 100
  257. #endif
  258.  
  259. /*
  260.  * Substitute Tcl's own versions for several system calls.  The
  261.  * Tcl versions retry automatically if interrupted by signals.
  262.  * (see tclUnixUtil.c).
  263.  */
  264.  
  265. #define open(a,b,c) TclOpen(a,b,c)
  266. #define read(a,b,c) TclRead(a,b,c)
  267. #define waitpid(a,b,c) TclWaitpid(a,b,c)
  268. #define write(a,b,c) TclWrite(a,b,c)
  269. EXTERN int    TclOpen _ANSI_ARGS_((char *path, int oflag, int mode));
  270. EXTERN int    TclRead _ANSI_ARGS_((int fd, char *buf, size_t numBytes));
  271. EXTERN int    TclWaitpid _ANSI_ARGS_((pid_t pid, int *statPtr, int options));
  272. EXTERN int    TclWrite _ANSI_ARGS_((int fd, char *buf, size_t numBytes));
  273.  
  274. /*
  275.  * Variables provided by the C library:
  276.  */
  277.  
  278. #if defined(_sgi) || defined(__sgi)
  279. #define environ _environ
  280. #endif
  281. extern char **environ;
  282.  
  283. #endif /* _TCLUNIX */
  284.